package main;

import gnu.io.CommPortIdentifier;
import gnu.io.NoSuchPortException;
import gnu.io.PortInUseException;
import gnu.io.SerialPort;
import gnu.io.UnsupportedCommOperationException;

public class TestOpenClose {
	public static void main(String[] args) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException {
		if (args.length < 1) {
			System.out.println("Usage: java TestOpenClose portName");
			System.exit(1);
		}
		
		String portName = args[0];
		
		CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
		SerialPort serialPort = (SerialPort)portIdentifier.open("TestOpenClose",2000);
		serialPort.setSerialPortParams(57600, SerialPort.DATABITS_8,
				SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
		
		System.out.println("Trying to close");
		serialPort.close();
		System.out.println("closed!");
	}
}
